<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="apk签名" prop="qianMing">
        <el-input
          v-model="queryParams.qianMing"
          placeholder="请输入apk签名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="是否被篡改" label-width="100px" prop="shiFouChuanGai">
        <el-select
          v-model="queryParams.shiFouChuanGai"
          placeholder="是否被篡改"
          clearable
          style="width: 240px"
        >
          <el-option
            :key="0"
            label="没有"
            :value="0"
          />
          <el-option
            :key="1"
            label="有"
            :value="1"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['app_bao_hu:table_app:list']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['app_bao_hu:table_app:list']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['app_bao_hu:table_app:list']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['app_bao_hu:table_app:list']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="table_an_zhuangList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="设备的id" align="center" prop="sheBeiId" />
      <el-table-column label="包名" align="center" prop="baoMing" />

      <el-table-column label="apk签名" align="center" prop="qianMing">
        <template slot-scope="scope">
          <span v-if="scope.row.shiFouChuanGai===1" style="color: red">{{scope.row.qianMing}}</span>
          <span v-else style="">{{scope.row.qianMing}}</span>
        </template>
      </el-table-column>

<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->


<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['app_bao_hu:table_app:list']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['app_bao_hu:table_app:list']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改apk安装信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备的id" prop="sheBeiId">
          <el-input v-model="form.sheBeiId" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="包名" prop="baoMing">
          <el-input v-model="form.baoMing" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="apk签名" prop="qianMing">
          <el-input v-model="form.qianMing" placeholder="请输入apk签名" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>






    <el-row>


      <el-col :span="7" class="card-box">
        <el-card>
          <div slot="header"><span>篡改统计</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <div ref="commandstats" style="height: 300px" />
          </div>
        </el-card>
      </el-col>


    </el-row>










  </div>
</template>

<script>
import { listTable_an_zhuang, getTable_an_zhuang, delTable_an_zhuang, addTable_an_zhuang, updateTable_an_zhuang,get_cuan_gai_shu_ju } from "@/api/app_bao_hu/table_an_zhuang";
import echarts from "echarts";


export default {
  name: "Table_an_zhuang",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // apk安装信息表格数据
      table_an_zhuangList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sheBeiId: null,
        baoMing: null,
        qianMing: null,
        shiFouChuanGai: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    const baoMing = this.$route.params && this.$route.params.baoMing;
    const qianMing = this.$route.params && this.$route.params.qianMing;
    console.log(qianMing)
    this.queryParams.baoMing=baoMing
    this.getList();
    this.get_cuan_gai_shu_ju_fun()





  },
  methods: {
    /** 查询apk安装信息列表 */
    getList() {
      this.loading = true;
      listTable_an_zhuang(this.queryParams).then(response => {
        this.table_an_zhuangList = response.rows;
        this.total = response.total;
        this.loading = false;
      });








    },



    get_cuan_gai_shu_ju_fun(){


      get_cuan_gai_shu_ju(this.queryParams).then(response => {

        console.log(response)

        let msg=JSON.parse(response.msg)

        //let data=[{name:"被篡改",value:2},{name:"正常",value:5}];
        let data=[];


        for(let i=0;i<msg.length;i++){
          let obj=msg[i]
          let obj1={}
          if(obj.shi_fou_chuan_gai){
            obj1.name="被篡改"
            obj1.value=obj.count
          }else{
            obj1.name="正常"
            obj1.value=obj.count
          }
          data[i]=obj1
        }


        this.commandstats = echarts.init(this.$refs.commandstats,"macarons");




        this.commandstats.setOption({
          tooltip: {
            trigger: "item",
            //formatter: "{a} <br/>{b} : {c} ({d}%)",
          },
          series: [
            {
              //name: "命令",
              type: "pie",
              roseType: "radius",
              radius: [15, 95],
              center: ["50%", "38%"],
              data: data,
              animationEasing: "cubicInOut",
              animationDuration: 1000,
            },
          ],
        });


      });

    },



    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        anZhuangId: null,
        sheBeiId: null,
        baoMing: null,
        qianMing: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.anZhuangId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加apk安装信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const anZhuangId = row.anZhuangId || this.ids
      getTable_an_zhuang(anZhuangId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改apk安装信息";
      });
    },
    /** 修改按钮操作 */
    cuan_gai_qing_kuang(row) {
      this.reset();
      const anZhuangId = row.anZhuangId || this.ids
      getTable_an_zhuang(anZhuangId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改apk安装信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.anZhuangId != null) {
            updateTable_an_zhuang(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTable_an_zhuang(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const anZhuangIds = row.anZhuangId || this.ids;
      this.$modal.confirm('是否确认删除apk安装信息编号为"' + anZhuangIds + '"的数据项？').then(function() {
        return delTable_an_zhuang(anZhuangIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('app_bao_hu/table_an_zhuang/export', {
        ...this.queryParams
      }, `table_an_zhuang_${new Date().getTime()}.xlsx`)
    },


  }

};
</script>
